package design.singleton;

import java.util.Optional;

/**
 * <p>
 * 懒汉式单例模式实现：
 * 线程安全
 * 延迟加载
 * 加锁释放锁占用资源
 * </P>
 *
 * @author dingwen
 * @date 2021.10.14 15:49
 */
public class Singleton2 {
    private static Singleton2 instance;

    private Singleton2() {
    }

    public static synchronized Singleton2 getInstance() {
        return Optional.ofNullable(instance).orElseGet(Singleton2::new);
    }
}
